package com.example.transaction.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.QueueBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {

    public static final String ORDER_EXPIRATION_QUEUE = "order.expiration.queue";
    public static final String ORDER_EXPIRATION_EXCHANGE = "order.expiration.exchange";
    public static final String ORDER_EXPIRATION_ROUTING_KEY = "order.expiration.routing.key";

    @Bean
    public Queue orderExpirationQueue() {
        return QueueBuilder.durable(ORDER_EXPIRATION_QUEUE)
                .withArgument("x-dead-letter-exchange", ORDER_EXPIRATION_EXCHANGE)
                .withArgument("x-dead-letter-routing-key", ORDER_EXPIRATION_ROUTING_KEY)
                .build();
    }

    @Bean
    public DirectExchange orderExpirationExchange() {
        return new DirectExchange(ORDER_EXPIRATION_EXCHANGE);
    }

    @Bean
    public Binding orderExpirationBinding() {
        return BindingBuilder.bind(orderExpirationQueue())
                .to(orderExpirationExchange())
                .with(ORDER_EXPIRATION_ROUTING_KEY);
    }
}
